/**
* This is the Platform for the OBDX Framework.
* @module Platform
*/
define(["jquery", "promise"], function($, Promise) {
"use strict";
/**
* @summary This is the constructor for the Platform.
* @class
* @alias Platform
* @memberof module:platform
* @description This constructor returns three methods:
* info : Used as Logger.info, where Logger is the instance of BaseLogger.
* error : Used as Logger.error, where Logger is the instance of BaseLogger.
* warn : Used as Logger.warn, where Logger is the instance of BaseLogger.
*/
var Platform = function(resolve) {
var self = this,
platform;
var behaviours = {};
self.callBehaviour = function() {
if (behaviours[arguments[0]]) {
var args = [].slice.call(arguments).splice(1);
return behaviours[arguments[0]].apply(this, args);
}
return null;
};
if (window.navigator.userAgent.indexOf("OIC-Authentication") !== -1) {
platform = "mobile";
} else {
platform = "default";
}
require(["framework/js/base-models/platform/" + platform], function(operations) {
$.extend(behaviours, operations);
behaviours.init(self.callBehaviour, resolve);
});
};
var promise = new Promise(function(resolve) {
new Platform(resolve);
});
return {
/**
* Get the Platform Base instance. Checks [instance]{@linkcode module:platform~instance} for instance. If exists, returns it, else invokes [createInstance]{@linkcode module:platform~createInstance} to create an instance and returns it.
* @function getInstance
* @memberof module:platform
* @static
* @returns {Platform} The base service instance.
*/
getInstance: function() {
return promise;
}
};
});